/**
 * 门诊页面JS
 * @author zyl
 */

/**
 * 门诊页面数据表格属性配置
 */
$('#org_dataClinicGrid').datagrid({ 
	url:'statisticsOutpatient/getMzListByOrgId',
	queryParams:{orgId:orange.getOrganizationData().id},
    singleSelect:true,
    rownumbers:true,
    columns:[[ 
        {field:'month',title:'月份',width:'11%',halign:'center'},
        {field:'amountNormal',title:'常规门诊人数',width:'10%',halign:'center'}, 
        {field:'amountRemote',title:'远程门诊人数',width:'10%',halign:'center'},
        {field:'amountPreliminary',title:'初诊人数',width:'8%',halign:'center'},
        {field:'amountSubsequent',title:'复诊人数',width:'8%',halign:'center'},
        {field:'amountTheLocal',title:'本地就诊人数',width:'8%',halign:'center'}, 
        {field:'amountTheForeigner',title:'外来就诊人数',width:'8%',halign:'center'}, 
        {field:'amountTotal',title:'门诊总人次',width:'10%',halign:'center',formatter:clinicSum_option}, 
        {field:'totalPrescriptionAmount',title:'门诊中药方总数',width:'10%',halign:'center'}, 
        {field:'tcmPrescriptionEarnings',title:'门诊中药方总金额',width:'15%',halign:'center'} 
    ]],
    pagination:true
});
//门诊总人次=常规门诊人数+远程门诊人数
function clinicSum_option(value,rows){
	return (rows.amountNormal+rows.amountRemote);
}
// 添加门诊信息页面
function add_dataClinic() {
	$('#add_dataClinic').form('clear');
	$('#password-css').css({'display' : 'none'});
	$('input:radio[name="readonly"][value="0"]').prop('checked', true);
	$('#org_add_dataClinic').window('open');
}
//修改技师页面信息
function update_dataClinic() {
	$('#update_dataClinic').form('clear');
	$('#password-css').css({'display':'none'});
	//获取选中的行
	var doctorGrid = $("#org_dataClinicGrid");
	var selections = doctorGrid.datagrid("getSelections");
	if(selections.length == 0){
		$.messager.alert('提示','请选择需要修改的记录！'); 
	}else if(selections.length > 1){
		$.messager.alert('提示','请勿多选！'); 
	}else{
		var data = selections[0];
		var id = data.id;
		$('#update_dataClinic').form('load', data);
		$('#org_update_dataClinic').window('open');
	}
};
//添加门诊信息页面确定按钮
function add_dataClinic_saveOK() {
	var jsonData = orange.systemPage.getFormData('add_dataClinic');
		jsonData['orgGuid'] = orange.getOrganizationData().id;
	    var submitFlag = $('#org_add_dataClinic').form('validate'); 
		if(submitFlag==true){
			if(data_clinicMonth_isExist()==true){
				return ;
			}else{
				$.ajax({
			        url:'statisticsOutpatient/add',
			        type: 'post',
			        data: jsonData,
			        success: function(){
			        	$.messager.show({
			    			title:'提示',
			    			msg:'添加成功',
			    		});
			            $('#org_add_dataClinic').window('close');
			            $('#org_dataClinicGrid').datagrid('reload');    
			        }
			    });
			}
		}else{
			$.messager.alert('我的消息','不能保存，还有必填项未填写！');
			return;
		}
}
//添加门诊信息页面取消按钮
function add_dataClinic_cancelOK() {
	$('#org_add_dataClinic').window('close');
}
//修改门诊信息页面确定按钮
function update_dataClinic_saveOK() {
	var jsonData = orange.systemPage.getFormData('update_dataClinic');
	jsonData['orgGuid'] = orange.getOrganizationData().id;
    var submitFlag = $('#org_update_dataClinic').form('validate'); 
	if(submitFlag==true){
			$.ajax({
		        url:'statisticsOutpatient/edit',
		        type: 'post',
		        data: jsonData,
		        success: function(){
		        	$.messager.show({
		    			title:'提示',
		    			msg:'修改成功',
		    		});
		            $('#org_update_dataClinic').window('close');
		            $('#org_dataClinicGrid').datagrid('reload');    
		        }
		    });
	}else{
		$.messager.alert('我的消息','不能保存，还有必填项未填写！');
		return;
	}
}
//修改门诊信息页面取消按钮
function update_dataClinic_cancelOK() {
	$('#org_update_dataClinic').window('close');
}
//设置添加门诊信息页面初始化信息
$("#org_add_dataClinic").window({
	width:'50%',
	collapsible: false,
	resizable: false
	});
//验证添加输入的月份是否存在
function data_clinicMonth_isExist() {
	var flag=true;
	var month = $('#add_dataClinic_month').val();
	$.ajax({
        url:'statisticsOutpatient/checkMonth',
        type: 'post',
        async:false,
        data: {
        	month:month,
        	orgGuid:orange.getOrganizationData().id
        },
        success: function(data){
        	if(data && data == true) {
        		$.messager.show({
        			title:'操作提示',
        			msg:'您所选择的月份已存在 ，请重新选择月份或者修改已有月份！！'
        		});
        		return flag;
        	}
        	flag = false;
        }
	});
	return flag;
}